package de.hhkk.view.stammdaten;

import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.nebula.widgets.calendarcombo.CalendarCombo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;

import de.hhkk.controller.NavigationController;
import de.hhkk.model.stammdaten.Stammdaten;

public class UIStammdatenBearbeitung extends Composite
{
    private Text txtKundenNr;
    private Text text_1;
    private Text txtArt;
    private Text txtVorname;
    private Text txtName;
    private Text txtStrasse;
    private Text txtEmail;
    private Text txtTel;
    private Text text_8;
    private Text text_9;
    private Text text_10;
    private Text txtOrt;
    private Text txtPLZ;
    private boolean flgNeuanlage;
    private Stammdaten    stammdaten;

    /**
     * Create the composite.
     * @param parent
     * @param style
     */
    public UIStammdatenBearbeitung(Composite parent, int style, String title, Stammdaten stammdaten, boolean flgNeuanlage)
    {
        super(parent, style);
        this.stammdaten = stammdaten;
        this.flgNeuanlage = flgNeuanlage;
        setLayout(new FillLayout(SWT.HORIZONTAL));
        TabFolder tabFolder = new TabFolder(this, SWT.NONE);
        tabFolder.setBounds(0, 0, 122, 43);

        TabItem tbtmNewItem = new TabItem(tabFolder, SWT.NONE);
        tbtmNewItem.setText(title);

        Composite composite = new Composite(tabFolder, SWT.NONE);
        tbtmNewItem.setControl(composite);
        composite.setLayout(new GridLayout(1, false));

        Group group = new Group(composite, SWT.NONE);
        GridData gd_group = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
        gd_group.heightHint = 172;
        gd_group.widthHint = 660;
        group.setLayoutData(gd_group);
        group.setText("Suchkriterien");
        group.setBounds(0, 0, 650, 227);
        group.setLayout(new GridLayout(8, false));

        Label lblKundennr = new Label(group, SWT.NONE);
        lblKundennr.setText("Kunden-Nr.");

        txtKundenNr = new Text(group, SWT.BORDER);
        GridData gd_txtKundenNr = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
        gd_txtKundenNr.widthHint = 140;
        txtKundenNr.setLayoutData(gd_txtKundenNr);

        Label lblNewLabel_2 = new Label(group, SWT.NONE);
        lblNewLabel_2.setText("Stra\u00DFe");

        txtStrasse = new Text(group, SWT.BORDER);
        txtStrasse.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Label lblNewLabel_5 = new Label(group, SWT.NONE);
        lblNewLabel_5.setText("Land");

        text_8 = new Text(group, SWT.BORDER);
        text_8.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Label label_1 = new Label(group, SWT.SEPARATOR);
        label_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 6));
        new Label(group, SWT.NONE);

        Label lblArt = new Label(group, SWT.NONE);
        lblArt.setText("Art");

        txtArt = new Text(group, SWT.BORDER);
        txtArt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Label lblOrt = new Label(group, SWT.NONE);
        lblOrt.setText("Ort");

        txtOrt = new Text(group, SWT.BORDER);
        txtOrt.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

        Label lblNewLabel_6 = new Label(group, SWT.NONE);
        lblNewLabel_6.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_6.setText("Grundkenntnisse");

        text_9 = new Text(group, SWT.BORDER);
        text_9.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        new Label(group, SWT.NONE);

        Label lblBezeichnung = new Label(group, SWT.NONE);
        lblBezeichnung.setText("Anrede");

        text_1 = new Text(group, SWT.BORDER);
        text_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Label lblPlz = new Label(group, SWT.NONE);
        lblPlz.setText("PLZ");

        txtPLZ = new Text(group, SWT.BORDER);
        txtPLZ.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

        Label lblNewLabel_7 = new Label(group, SWT.NONE);
        lblNewLabel_7.setText("Geburtsdatum");

        CalendarCombo calendarCombo = new CalendarCombo(group, SWT.NONE);

        Button button = new Button(group, SWT.NONE);
        button.setText("Suchen");

        Label lblNewLabel = new Label(group, SWT.NONE);
        lblNewLabel.setText("Vorname");

        txtVorname = new Text(group, SWT.BORDER);
        txtVorname.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Label lblNewLabel_3 = new Label(group, SWT.NONE);
        lblNewLabel_3.setText("E-Mail");

        txtEmail = new Text(group, SWT.BORDER);
        txtEmail.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Label lblNewLabel_8 = new Label(group, SWT.NONE);
        lblNewLabel_8.setText("IBAN");

        text_10 = new Text(group, SWT.BORDER);
        text_10.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        new Label(group, SWT.NONE);

        Label lblNewLabel_1 = new Label(group, SWT.NONE);
        lblNewLabel_1.setText("Name");

        txtName = new Text(group, SWT.BORDER);
        txtName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Label lblNewLabel_4 = new Label(group, SWT.NONE);
        lblNewLabel_4.setText("Tel.");

        txtTel = new Text(group, SWT.BORDER);
        txtTel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);

        Label label_8 = new Label(group, SWT.NONE);
        label_8.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));

        Label label_9 = new Label(group, SWT.NONE);
        GridData gd_label_9 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
        gd_label_9.widthHint = 69;
        label_9.setLayoutData(gd_label_9);
        Label label_3 = new Label(group, SWT.NONE);
        label_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        Label label_6 = new Label(group, SWT.NONE);
        label_6.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);

        Composite composite_1 = new Composite(composite, SWT.NONE);
        GridData gd_composite_1 = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
        gd_composite_1.widthHint = 164;
        composite_1.setLayoutData(gd_composite_1);
        composite_1.setBounds(0, 0, 157, 35);
        composite_1.setLayout(new GridLayout(2, false));

        Button btnSpeichern = new Button(composite_1, SWT.NONE);
        btnSpeichern.setText("Speichern");

        Button btnSchliessen = new Button(composite_1, SWT.NONE);
        btnSchliessen.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent e)
            {
                NavigationController.getInstance().clear();
                dispose();
            }
        });
        btnSchliessen.setText("Schlie\u00DFen");

    }

    @Override
    protected void checkSubclass()
    {
        // Disable the check that prevents subclassing of SWT components
    }
    private DataBindingContext initDataBindings()
    {
        Realm realm = SWTObservables.getRealm(getDisplay());
        DataBindingContext context = new DataBindingContext(realm);

        // Suchkriterien
        Binding bindValue = context.bindValue(SWTObservables.observeText(txtName, SWT.FocusOut),
                BeansObservables.observeValue(realm,stammdaten, "name"));
        context.bindValue(SWTObservables.observeText(txtVorname, SWT.FocusOut),
                BeansObservables.observeValue(realm,stammdaten, "vorname"));
        context.bindValue(SWTObservables.observeText(txtOrt, SWT.FocusOut),
                BeansObservables.observeValue(realm,stammdaten, "ort"));     
        
        return context;
    }

    
}
